package com.mediacloud.app.newsmodule.activity.military_encyclopedia

import android.graphics.drawable.Drawable
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.mediacloud.app.assembly.util.StringUtils
import com.mediacloud.app.newsmodule.R
import com.mediacloud.app.newsmodule.adaptor.component.WikiRankList

class WikiListAdapter : BaseQuickAdapter<WikiRankList, BaseViewHolder>(R.layout.item_wiki_adapter) {
    var rankType: Int = 0//1热度榜单2评论榜单3权重榜单
    override fun convert(helper: BaseViewHolder, item: WikiRankList) {

        val tvTitle = helper.getView<TextView>(R.id.tvTitle)
        val tvSort = helper.getView<TextView>(R.id.tvSort)
        val line = helper.getView<View>(R.id.splitLine)
        line.visibility = View.VISIBLE
        tvTitle.text = item.title
        tvSort.text = ""
        var drawable: Drawable? = null
        when (helper.absoluteAdapterPosition) {
            0 -> drawable = ContextCompat.getDrawable(tvTitle.context, R.drawable.icon_bk_top1)

            1 -> drawable = ContextCompat.getDrawable(tvTitle.context, R.drawable.icon_bk_top2)

            2 -> drawable = ContextCompat.getDrawable(tvTitle.context, R.drawable.icon_bk_top3)

            3 -> drawable = ContextCompat.getDrawable(tvTitle.context, R.drawable.icon_bk_top4)

            4 -> drawable = ContextCompat.getDrawable(tvTitle.context, R.drawable.icon_bk_top5)

            5 -> drawable = ContextCompat.getDrawable(tvTitle.context, R.drawable.icon_bk_top6)

            6 -> drawable = ContextCompat.getDrawable(tvTitle.context, R.drawable.icon_bk_top7)

            7 -> drawable = ContextCompat.getDrawable(tvTitle.context, R.drawable.icon_bk_top8)

            8 -> drawable = ContextCompat.getDrawable(tvTitle.context, R.drawable.icon_bk_top9)

            else-> {
                tvSort.text = "${helper.absoluteAdapterPosition + 1}  "
                drawable = null
            }
        }
        tvTitle.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
        helper.setText(R.id.tvIntro, item.shortTitle)
        if (rankType == 3) {
            helper.setText(R.id.tvHotNum, StringUtils.toTenThousand(item.virtualCount))
        } else helper.setText(R.id.tvHotNum, StringUtils.toTenThousand(item.hitCount))
    }


}